Promise.myAny = function (promises) {
  return new Promise((resolve, reject) => {
    const errs = [];
    let count = 0;
    for (let i = 0; i < promises.length; i++) {
      Promise.resolve(promises[i]).then((item) => {
        resolve(item);
      }).catch((err) => {
        errs[i] = err;
        count++;
        if (count === promises.length) {
          reject(new AggregateError(errs, 'All promises were rejected'));
        }
      })
    }
    if (!promises.length) {
      reject(new AggregateError('All promises were rejected'));
    }
  });
};

const promises = [
  Promise.reject('ERROR A'),
  Promise.reject('ERROR B'),
  Promise.reject('ERROR C'),
  // Promise.resolve('result'),
];

Promise.any(promises).then((value) => {
  console.log('value: ', value)
}).catch((err) => {
  console.log('err: ', err)
})

Promise.any(promises).then((value) => {
  console.log('value：', value)
}).catch((err) => {
  console.log('err：', err)
  console.log(err.message)
  console.log(err.name)
  console.log(err.errors)
})

// value:  result

Promise.myAny(promises)
  .then((value) => {
    console.log('value: ', value);
  })
  .catch((err) => {
    console.log('err: ', err);
  });

Promise.myAny(promises)
  .then((value) => {
    console.log('value：', value);
  })
  .catch((err) => {
    console.log('err：', err);
    console.log(err.message);
    console.log(err.name);
    console.log(err.errors);
  });

